//
// Created by francklinson on 2021/11/17 AT 23:18.
// May Saint Diana bless you!
//

#include <iostream>


using namespace std;

class Solution {
public:
    bool hasAlternatingBits(int n) {
        // 错位异或 如果是满足条件的，必然的到全是1的一个数 +1后得到第一位为1的数
        // 再用m&(m-1)消除最后一位1
        long m = n ^ (n >> 1) ;
        return (m & (m + 1))==0;
    }
};

int main() {
    Solution solution;
    cout << solution.hasAlternatingBits(5) << endl;
    cout << solution.hasAlternatingBits(7) << endl;
    cout << solution.hasAlternatingBits(11) << endl;
    cout << solution.hasAlternatingBits(10) << endl;
    cout << solution.hasAlternatingBits(3) << endl;
    return 0;
}

